#!/usr/bin/env python
# encoding: utf-8
'''
@author: aliax
@license: (C) Copyright 2018-2020.
@contact: 1048327635@qq.com
@file: db.py
@time: 2020/7/8 0008 21:46
@desc:
'''
from redis import ConnectionPool,StrictRedis
import Config.config as config

db_host = config.DB_HOST
db_port = config.DB_PORT
db_passwd = config.DB_PASSWORD
pool = ConnectionPool(host=db_host, port=db_port, db=0, password=db_passwd)
redis = StrictRedis(connection_pool=pool)

def set(name,key,value):
    """
    封装hset方法
    :param type:
    :param value:
    :return:
    """
    redis.hset(name,key,str(value))

def get(name,key):
    """
    封装hget方法
    :param type:
    :param key:
    :return:
    """
    return redis.hget(name,key)


def exists(type,key):
    """
    封装hexists方法
    :param type:
    :param value:
    :return:
    """
    redis.hexists('all',key)

def delete(name,key):
    """
    封装hdel方法
    :param type:
    :param value:
    :return:
    """
    redis.hdel(name,key)

def keys(name):
    """
    封装获取所有keys的方法
    :param type:
    :return:
    """
    return redis.hkeys(name)

def len(name):
    """
    封装hlen方法
    :param name:
    :return:
    """
    return redis.hlen(name)